package com.sike.service;

import com.sike.entity.Drug;
import com.sike.mapper.DrugMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DrugService {
    private final DrugMapper drugMapper;

    @Autowired
    public DrugService(DrugMapper drugMapper) {
        this.drugMapper = drugMapper;
    }

    // 查询所有药品，返回List集合
    public List<Drug> findAllDrugs() {
        return drugMapper.findAllDrugs();
    }

    // 根据id查询药品，返回Drug对象
    public Drug findDrugById(Integer id) {
        return drugMapper.findDrugById(id);
    }

    // 添加新药品
    public void addDrug(Drug drug) {
        drugMapper.addDrug(drug);
    }

    // 更新药品信息
    public void updateDrug(Drug drug) {
        drugMapper.updateDrug(drug);
    }

    // 删除药品
    public void deleteDrug(Integer id) {
        drugMapper.deleteDrug(id);
    }

    // 搜索药品，返回List集合
    public List<Drug> searchDrugsByName(String name) {
        return drugMapper.searchDrugsByName(name);
    }

    // 更新药品图片
    public void updateDrugImage(int drugId, String imageUrl) {
        drugMapper.updateDrugImage(drugId, imageUrl);
    }
}



